<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('未出款数据')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<input type="hidden" name="ordernumber" th:value="${ordernumber}">
						<input type="hidden" name="type" th:value="${type}">
						<input type="hidden" name="searchType" th:value="${searchType}">
						<ul>
							<li>
								<label  style="width: 80px;">流水号：</label>
								<input type="text" name="settle_serial"/>
							</li>
							<li>
								<label style="width: 80px;">服务商编号：</label>
								<input type="text" name="agent_num"/>
							</li>
							<li>
								<label style="width: 80px;">服务商名称：</label>
								<input type="text" name="agent_name"/>
							</li>
							<li>
								<label style="width: 80px;">结算类型：</label>
								<select name="profit_type" th:with="type=${@dict.getType('profit_type_paid')}">
									<option value="">请选择</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label style="width: 80px;">结算周期：</label>
								<select name="cycle">
									<option value="">请选择</option>
									<option value="0">日返</option>
									<option value="1">月返</option>
								</select>
							</li>
							<li>
								<label style="width: 80px;">账户类型：</label>
								<select name="nature">
									<option value="">请选择</option>
									<option value="1">对公</option>
									<option value="2">对私</option>
								</select>
							</li>
							<li>
								<label style="width: 80px;">机具类型：</label>
								<select name="agent_type" th:with="type=${@dict.getType('terminal_type')}">
									<option value="">请选择</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<label style="width: 80px;">结算卡号：</label>
								<input type="text" name="screen_num"/>
							</li>
							<li>
								<label style="width: 80px;">结算人：</label>
								<input type="text" name="screen_name"/>
							</li>
							<li>
								<label style="width: 80px;">最低金额：</label>
								<input type="text" name="lower_money"/>
							</li>
							<li class="select-time">
								<label style="width: 80px;">日期：</label>
								<input type="text" class="time-input" readonly th:value="${mindDate}" id="startTime" placeholder="开始时间" name="mindDate"/>
								<span>-</span>
								<input type="text" class="time-input" readonly th:value="${maxDate}" id="endTime" placeholder="结束时间" name="maxDate"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 search-collapse">
				<span style="color:blue">[</span>
				<span style="color: blue;font-style: initial">结算总额：</span>
				<span id="amount" style="color: red;font-style: initial">0</span><span style="color: blue;font-style: initial"> 元</span>
				<span style="color:blue">]</span>
			</div>
			<div class="col-sm-12 search-collapse">
				<span th:each="order :${list}" th:switch="${order.ORDERTYPE}">
					<a th:case="'1'" class="btn btn-success multiple" onclick="addDataToOrder(this)" th:attr="orderNo=${order.ORDERNUMBER},state=${order.STATE}" th:title="${order.ORDERNUMBER+'&#10'+'[代付对公]'+'&#10'+'出款总商户数:'+order.SUMTRADE+'&#10'+'出款总笔数:'+order.SUMCOUNT+'&#10'+'交易总金额：'+order.SUMAMOUNT+'&#10'+'应出款金额：'+order.PAY_MONEY+'&#10'}" shiro:hasPermission="agentInfo:profitSbOrder:addDataToOrder">
						<span th:if="${order.STATE == 3}" th:text="${order.ORDERNUMBER+'[对公-已填单]'}"></span>
						<span th:if="${order.STATE == 2}" th:text="${order.ORDERNUMBER+'[对公-未填单]'}"></span>
					</a>
					<a th:case="*" class="btn btn-success multiple" onclick="addDataToOrder(this)" th:attr="orderNo=${order.ORDERNUMBER},state=${order.STATE}"  th:title="${order.ORDERNUMBER+'&#10'+'[代付对公]'+'&#10'+'出款总商户数:'+order.SUMTRADE+'&#10'+'出款总笔数:'+order.SUMCOUNT+'&#10'+'交易总金额：'+order.SUMAMOUNT+'&#10'+'应出款金额：'+order.PAY_MONEY+'&#10'}" shiro:hasPermission="agentInfo:profitSbOrder:addDataToOrder">
						<span th:if="${order.STATE == 3}" th:text="${order.ORDERNUMBER+'[对私-已填单]'}"></span>
						<span th:if="${order.STATE == 2}" th:text="${order.ORDERNUMBER+'[对私-未填单]'}"></span>
					</a>
				</span>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="addOrder()" shiro:hasPermission="agentInfo:profitSbOrder:addOrder">
					<i class="fa fa-plus"></i> 添加订单
				</a>
				<!--<a class="btn btn-success" onclick="fillBill()" shiro:hasPermission="agentInfo:profitSbOrder:fillBill">
					<i class="fa fa-plus"></i> 选择填单
				</a>-->
				<a class="btn btn-success" onclick="allOrder()" shiro:hasPermission="agentInfo:profitSbOrder:fillBill">
					<i class="fa fa-plus"></i> 一键填单
				</a>
				<a class="btn btn-danger multiple disabled" onclick="frozen()" shiro:hasPermission="agentInfo:profitSbOrder:frozen">
					<i class="fa fa-remove"></i> 冻结出款
				</a>
				<a class="btn btn-success" onclick="$.table.exportExcel()" >
					<i class="fa fa-download"></i> 导出
				</a>
				<br>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "agentInfo/profitSbOrder";

		var terminalTypeDatas = [[${@dict.getType('terminal_type')}]];
		var profit_type_paid = [[${@dict.getType('profit_type_paid')}]];


		$(function()  {
            var options = {
				exportUrl: prefix + "/exportSettleInfo",
				url: prefix + "/unPayList",
				modalName: "分润未出款",
				showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
	            clickToSelect:true,
				responseHandler:responseHandler,
				columns: [{
		            checkbox: true
		        },
                {
                    field : 'SETTLE_ID',
                    title : '主键',
                    visible: false
                },
				{
					field : 'SETTLE_SERIAL',
					title : '流水号',
					width: "300",
					formatter:function (value, row, index) {
						return value+$.table.tooltip('[备注]'+row.NOTE,4);
					}
				},
				{
					field : 'AGENT_NUM',
					title : '服务商编号'
				},
				{
					field : 'AGENT_NAME',
					title : '服务商名称',
					formatter:function (value, row, index) {
						return $.table.tooltip(value,4);
					}
				},
				{
					field : 'AUDITDATE',
					title : '生成日期'
				},
				{
					field : 'PROFIT_TYPE',
					title : '类型',
					formatter:function(value,row,index){
						return $.table.selectDictLabel(profit_type_paid, value);
					}
				},
				{
					field : 'CYCLE',
					title : '周期',
					formatter: function(value, row, index) {
						if ("0"==value){
							return '<span style="color:blue;">日返</span>';
						}else if("1"==value){
							return '<span style="color:green;">月返</span>';
						}else{
							return '<span style="color:red;">未知</span>';
						}
					}
				},
				{
					field : 'NATURE',
					title : '账户类型',
					formatter: function(value, row, index) {
						if ("1" == value){
							return '<span style="color:blue;">对公</span>';
						}else if("2" == value){
							return '<span style="color:green;">对私</span>';
						}else{
							return '<span style="color:red;">未知</span>';
						}
					}
				},
				{
					field : 'BANK_NAME',
					title : '开户行名称'
				},
				{
				    field : 'BANK_HEADNAME',
				    title : '总行名称'
				},
				{
					field : 'SCREEN_NAME',
					title : '结算人'
				},
				{
					field : 'SHOW_SCREENNUM',
					title : '结算卡'
				},
				{
					field : 'MONEY',
					title : '结算金额(元)',
					formatter: function(value, row, index) {
						return $.table.rmbFormatter(value);
					}
				},
				{
					field : 'PAY_TIME',
					title : '付款时间'
				},

				{
					field : 'STATUS',
					title : '出款状态',
					formatter: function(value, row, index) {
						if ("0"==value){
							return '<span style="color:blue;">待处理</span>';
						}else if("1"==value){
							return '<span style="color:green;">出款成功</span>';
						}else if("-2"==value){
							return '<span style="color:#880000;">出款失败</span>';
						}else if("-3"==value){
							return '<span style="color:green;">冻结</span> ';
						}else if("-1"==value){
							return '<span style="color:green;">已上送</span>';
						}else{
							return '<span style="color:red;">出款失败</span>';
						}
					}
				},
				{
					field : 'AGENT_TYPE',
					title : '机具类型',
					formatter:function(value,row,index){
						return $.table.selectDictLabel(terminalTypeDatas, value);
					}
				},]
            };
            $.table.init(options);
        });
		function addOrder() {
			$.modal.open("添加订单",prefix + "/addOrder",'400','250');
		}
		function addDataToOrder(obj) {
			var state = $(obj).attr("state");
			if ('0'!=state){
				$.modal.alertWarning("该单已添加");
				return;
			}
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
			var orderNo = $(obj).attr("orderNo");
			$.modal.open("添加订单",prefix + "/batchBill?ids="+ rows.join()+"&orderNo="+ orderNo,'800');
		}
		function fillBill() {
		    $('#formId').serialize()
            $.modal.open("选择建单",prefix + "/fillBill",'400','250');
        }
		function allOrder() {

            $.modal.open("一键填单",prefix + "/allOrder?" + $('#formId').serialize(),'400','250');
        }
        function frozen() {
			table.set();
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			$.modal.open("冻结出款",prefix + "/frozen?ids="+ rows.join(),'800');
		}


		function responseHandler(res) {
			$("#amount").text($.common.isEmpty(res.data) ? 0 : res.data.MONEY);
		}

    </script>



</body>
</html>
